package com.example.beanlife.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;

/**
 * Bean的生命周期(五歩)
 * 1.实例化Bean(调用无参构造方法)
 * 2.给Bean属性赋值(调用set方法)
 * 3.初始化Bean(会调用Bean的init方法)
 * 4.使用Bean
 * 5.销毁Bean(调用destroy方法)
 *
 *
 * ClassName:User
 * Package:com.example.beanlife.bean
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/9-8:46
 * @Version:v1.0
 */
public class User implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware {

    private String name;

    public void setName(String name) {
        System.out.println("第二步：给对象属性赋值");
        this.name = name;
    }

    public User() {
        System.out.println("第一步：无参构造方法执行");
    }

    public void  initBean(){
        System.out.println("第四歩：初始化Bean");
    }

    public void destroyBean(){
        System.out.println("第七步：销毁bean");
    }

    @Override
    public String toString() {
        return "User{" +
               "name='" + name + '\'' +
               '}';
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("");
    }
}
